package com.glasses.service.imp;

import com.alibaba.fastjson.JSONObject;
import com.glasses.dao.IndentDao;
import com.glasses.dao.UserDao;
import com.glasses.orm.base.Ex.BaseServiceEx;
import com.glasses.orm.utils.ObjectUtils;
import com.glasses.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wangchao.tools.CreateKey;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by ashin on 2018/1/24.
 */
@Service
public class UserServiceImp extends BaseServiceEx implements UserService {

    @Autowired
    UserDao userDao;

    @Autowired
    IndentDao indentDao;

    @Override
    public void init() {
        super.init(userDao);
    }

    @Override
    public JSONObject login(Map map, HttpSession session) throws Exception {
        if (ObjectUtils.isEmpty(map.get("userName"))) {
            return this.codeMess(eCode, "用户名不能为空");
        }
        if (ObjectUtils.isEmpty(map.get("passWord"))) {
            return this.codeMess(eCode, "密码不能为空");
        }
        if (!"admin".equals(map.get("userName").toString())) {
            return this.codeMess(eCode, "用户名有误");
        }
        if (!"admin".equals(map.get("passWord").toString())) {
            return this.codeMess(eCode, "密码有误");
        }
        Map userMap = new HashMap();
        userMap.put("nickName", "超级管理员");
        userMap.put("token", CreateKey.getRandomNum(10));
        session.setAttribute("user", userMap);
        return this.codeData(userMap);
    }

    @Override
    public JSONObject getMyIndent(Map map) throws Exception {
        return this.codeData(userDao.getMyIndent(map));
    }

}
